import { FormType } from '@/base-ui/base-form/type'
import { IModalConfig } from '@/components/page-modal/type'
import { ActionDesc } from '@/global/constant'

const getShopListModalAddOrEdit = (isAdd = true): IModalConfig => {
  const config: IModalConfig = {
    modalProps: {
      title: isAdd ? '新增商品' : '编辑商品',
      width: 450,
      maskClosable: false,
      closable: false
    },
    formProps: {
      desc: isAdd ? ActionDesc.Add : ActionDesc.Edit,
      layout: { span: 24 },
      formConfig: {
        name: isAdd ? 'shop-list-add' : 'shop-list-edit',
        size: 'small',
        labelAlign: 'right',
        // labelCol: 输入框这些前面的文字的宽度
        labelCol: { flex: '85px' },
        // labelWrap：表单前面的label宽度(labelCol指定的flex)不够,那么他会进行自动换行
        // labelWrap: true,
        // wrapperCol: { flex: 1 },
        colon: false
        // style: { minWidth: 700 }
      },
      itemsConfig: [
        {
          type: FormType.Input,
          prop: 'shopName',
          name: 'shopName',
          label: '商品名称',
          rules: isAdd ? [{ required: true }] : [],
          input: {
            placeholder: '请输入商品名称'
          }
        },
        {
          type: FormType.Select,
          prop: 'shopStatus',
          name: 'shopStatus',
          label: '商品状态',
          rules: isAdd ? [{ required: true }] : [],
          select: {
            baseProps: {
              placeholder: '请选择商品状态'
            },
            options: [
              { value: 0, content: '下架' },
              { value: 1, content: '上架' }
            ]
          }
        },
        {
          type: FormType.InputNumber,
          prop: 'shopIntegral',
          name: 'shopIntegral',
          label: '所需积分',
          rules: isAdd ? [{ required: true }] : []
        },
        {
          type: FormType.InputNumber,
          prop: 'earlyWarningNum',
          name: 'earlyWarningNum',
          label: '库存预警数',
          rules: isAdd ? [{ required: true }] : [],
          inputNumber: {
            min: 2,
            max: 10
          }
        },
        {
          type: FormType.InputNumber,
          prop: 'shopNum',
          name: 'shopNum',
          label: '商品数量',
          rules: isAdd ? [{ required: true }] : [],
          inputNumber: {
            min: 1
          }
        },
        {
          type: FormType.Custom,
          prop: 'shopImage',
          name: 'shopImage',
          customkey: 'shopImage',
          label: '商品图片'
        }
      ]
    }
  }

  return config as IModalConfig
}

export default getShopListModalAddOrEdit
